package com.boang.file;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
    @author:sa
    @date:2024/12/13 9:24
*/
public class FileDemo {
    public static void main(String[] args) throws IOException {
//        m1();
//        m2();
        m3();
//        m4();
    }

    private static void m4() {
        long l=System.currentTimeMillis();
//        System.out.println(l);
        Date date = new Date(l);
//        System.out.println(date);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String string = dateFormat.format(date);
        System.out.println(string);
    }

    private static void m3() {
        File file = new File("C:\\Users\\sa\\Desktop\\12-12");
        File[] files = file.listFiles();
        for (File f:files) {
            long l=System.currentTimeMillis();
            Date date = new Date(l);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(f.getName()+","+dateFormat.format(date));
        }
    }

    private static void m2() {
        File file = new File("C:\\Users\\sa\\Desktop\\file\\a.text");
        file.delete();
        File dir = new File("C:\\Users\\sa\\Desktop\\file");
        dir.delete();
    }

    private static void m1() throws IOException {
        File dir = new File("C:\\Users\\sa\\Desktop\\file");
        dir.mkdir();//创建目录
        File file = new File("C:\\Users\\sa\\Desktop\\file\\a.text");
        file.createNewFile();
    }
}